<?php

namespace app\api\controller\cps;

use app\api\service\event\OperationService;
use app\lib\exception\event\OperationException;
use think\Request;

class Operation
{
    protected $Service;
    public function __construct()
    {
        $this->Service = OperationService::getInstance();
    }

    /**
     * @auth('视频列表','短视频cps')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function videoList(Request $request){
        $params  = $request->get();
        $result = $this->Service->getVideoList($params);
        return writeJson(201, $result, '视频列表');
    }

    /**
     * @auth('上传视频','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function videoAdd(Request $request){
        $params = $request->post();
        $headersList = get_headers($params["video_url"]);
        foreach ($headersList as $value ){
            $list = explode(":",$value);
            if ($list[0] == "Ohc-File-Size"){
                if (intval($list[1]) < 40960){
                    return writeJson(20002,'','视频大小不能小于40M',20002);
                }
            }
        }
        $this->Service->createtVideo($params);
        return writeJson(201, '', '上传视频成功');
    }

    /**
     * @auth('视频驳回','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function videoReject(Request $request){
        $params = $request->post();
        $this->Service->checkVideo($params,$type = "reject");
        return writeJson(201, '', '视频驳回成功');
    }

    /**
     * @auth('视频是否通过','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function videoPass(Request $request){
        $params = $request->post();
        $this->Service->checkVideo($params,$type = "pass");
        return writeJson(201, '', '审核通过');
    }

    /**
     * @auth('视频重新上传','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function videoBack(Request $request){
        $params = $request->post();
        $this->Service->videoBack($params);
        return writeJson(201,'','上传成功');
    }

    //视频链接回填
    public function backfillUrl(Request $request){
        $params = $request->post();
        $this->Service->checkVideo($params,$type = "back");
        return writeJson(201, '', '回填成功');
    }

    //分发重置
    public function reset(Request $request){
        $params = $request->post();
        $this->Service->reset($params);
        return writeJson(201,'','重置成功');
    }

    /**
     * @auth('汇总表查看','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function collect(Request $request){
        $params  = $request->get();
        $res = $this->Service->collect($params);
        return writeJson(201,$res,'获取成功');
    }

    /**
     * @auth('查看分发表分发表','短视频cps')
     * @param Request $request
     * @return \think\response\Json
     */
    public function distributeList(Request $request){
        $params  = $request->get();
        $res = $this->Service->distributeList($params);
        return writeJson(201,$res,'获取成功');
    }

    public function massUpload(Request $request){
        $params = $request->post();
        $this->Service->massUpload($params);
        return writeJson(201,"",'导入成功');
    }

    public function qnyUpload(Request $request){
        $params = $request->post();
        $this->Service->qnyUpload($params);
        return writeJson(201,"",'上传成功');
    }

    //淘宝分发
    public function distribute(Request $request){
        $params  = $request->get();
        $result = $this->Service->tDistribute($params);
        return writeJson(201,$result,'领取分发');
    }

    //京东分发
    public function jDistribute(Request $request){
        $params  = $request->get();
        $result = $this->Service->jDistribute($params);
        return writeJson(201,$result,'领取分发');
    }

    public function jBackFillUrl(Request $request){
        $params  = $request->post();
        $result = $this->Service->jBackFillUrl($params);
        return writeJson(201, '', '回填成功');
    }

    public function tBackFillUrl(Request $request){
        $params  = $request->post();
        $result = $this->Service->tBackFillUrl($params);
        return writeJson(201, '', '回填成功');
    }

    public function materialList(Request $request){
        $params = $request->get();
        $list = $this->Service->materialList($params);
        return writeJson(201, $list, '获取成功');
    }

    public function feedList(Request $request){
        $params = $request->get();
        $list = $this->Service->feedList($params);
        return writeJson(201, $list, '获取成功');
    }

    public function cpsAdd(Request $request){
        $params = $request->post();
        $this->Service->cpsAdd($params);
        return writeJson(201, "", '通过成功');
    }

    public function cpsReset(Request $request){
        $params = $request->post();
        $this->Service->cpsReset($params);
        return writeJson(201, "", '重置成功');
    }
    public function feedJdList(Request $request){
        $params = $request->get();
        $list = $this->Service->feedJdList($params);
        return writeJson(201, $list, '获取成功');
    }

    public function cpsJdReset(Request $request){
        $params = $request->get();
        $this->Service->cpsJdReset($params);
        return writeJson(201, "", '重置成功');
    }

    public function cpsJdAdd(Request $request){
        $params = $request->post();
        $this->Service->cpsJdAdd($params);
        return writeJson(201, "", '通过成功');
    }

    public function getAccount(Request $request){
        $params = $request->get();
        $account = $this->Service->getAccount($params);
        return writeJson(200,$account,'获取成功');
    }

    public function records(Request $request){
        $params = $request->post();
        $info = $this->Service->records($params);
        return writeJson(200,$info,'导入成功');
    }

    public function list(Request $request){
        $params = $request->get();
        $list = $this->Service->list($params);
        return writeJson(200,$list,"获取成功");
    }






}
